package com.ruoyi.hr.socialSecurity.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hr.socialSecurity.domain.HrSocialSecurity;
import com.ruoyi.hr.socialSecurity.service.IHrSocialSecurityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社保Controller
 *
 * @author xzshan
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/api/socialSecurity")
public class HrSocialSecurityController extends BaseController
{
    private String prefix = "hr/socialSecurity";

    @Autowired
    private IHrSocialSecurityService hrSocialSecurityService;

    @RequiresPermissions("api:socialSecurity:view")
    @GetMapping()
    public String socialSecurity()
    {
        return prefix + "/socialSecurity";
    }

    /**
     * 查询社保列表
     */
    @RequiresPermissions("api:socialSecurity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HrSocialSecurity hrSocialSecurity)
    {
        startPage();
        List<HrSocialSecurity> list = hrSocialSecurityService.selectHrSocialSecurityList(hrSocialSecurity);
        return getDataTable(list);
    }

    /**
     * 导出社保列表
     */
    @RequiresPermissions("api:socialSecurity:export")
    @Log(title = "社保", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HrSocialSecurity hrSocialSecurity)
    {
        List<HrSocialSecurity> list = hrSocialSecurityService.selectHrSocialSecurityList(hrSocialSecurity);
        ExcelUtil<HrSocialSecurity> util = new ExcelUtil<HrSocialSecurity>(HrSocialSecurity.class);
        return util.exportExcel(list, "socialSecurity");
    }

    /**
     * 新增社保
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社保
     */
    @RequiresPermissions("api:socialSecurity:add")
    @Log(title = "社保", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HrSocialSecurity hrSocialSecurity)
    {
        return toAjax(hrSocialSecurityService.insertHrSocialSecurity(hrSocialSecurity));
    }

    /**
     * 修改社保
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HrSocialSecurity hrSocialSecurity = hrSocialSecurityService.selectHrSocialSecurityById(id);
        mmap.put("hrSocialSecurity", hrSocialSecurity);
        return prefix + "/edit";
    }

    /**
     * 修改保存社保
     */
    @RequiresPermissions("api:socialSecurity:edit")
    @Log(title = "社保", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HrSocialSecurity hrSocialSecurity)
    {
        return toAjax(hrSocialSecurityService.updateHrSocialSecurity(hrSocialSecurity));
    }

    /**
     * 删除社保
     */
    @RequiresPermissions("api:socialSecurity:remove")
    @Log(title = "社保", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hrSocialSecurityService.deleteHrSocialSecurityByIds(ids));
    }
}
